<?php

namespace App\Repository\XhApi;

use App\Models\Xh\GridModel;
use App\Repository\BaseRepository;

class GridRepository extends BaseRepository
{
    public $model;
    public $log;

    public function __construct()
    {
        $this->model = new GridModel();
        parent::__construct();
    }

    public function index($params, $page = 1, $limit = 10)
    {
        $where = [];
        if (!empty($params['number'])) {
            $where['where']['number'] = $params['number'];
        }
        if (!empty($params['shop_id'])) {
            $where['where']['shop_id'] = $params['shop_id'];
        }
        if (isset($params['status']) && $params['status'] != '') {
            $where['where']['status'] = (int)$params['status'];
        }
        if (!empty($params['dateRange'])) {
            $time = $params['dateRange'];
            $where['between']['created_at'] = $time;
        }
        return $this->unifiedGetPage($where, $page, $limit);
    }

//    快速修改状态
    public function changeStatus($id, $status = 0, $shopId = 0)
    {
        return $this->unifiedUpdateStatus($id, $status, $shopId);
    }

//删除指定id的内容
    public function del($id, $shopId = 0)
    {
        return $this->unifiedDel($id, $shopId);
    }

//新增内容
    public function add($postData)
    {
        $shop_id = $postData['user']['shop_id'] ?? 0;
        return $this->unifiedAdd($postData, [
            'name' => '名称必填写',
            'pic' => '请上传图标'
        ], null, $shop_id);
    }

//修改内容
    public function edit($postData)
    {
        $shop_id = $postData['user']['shop_id'] ?? 0;
        return $this->unifiedEdit($postData, [
            'id' => '请指明修改的数据编号',
            'name' => '名称必填写',
            'pic' => '请上传图标'
        ], null, $shop_id);
    }
}
